<?php
namespace admin\controllers;

use common\models\Category;
use Yii;

/**
 * 分类管理
 */
class CategoryController extends BaseController
{
    public $modelClass = 'common\models\Category';
    public $searchModelClass = 'admin\models\CategorySearch';


    /**
     * 置顶
     */
    public function actionUp()
    {
        $id = Yii::$app->request->get('id');

        $categories = Category::find();
        foreach ($categories->each() as $category) {
            if ($category->id == $id) { //如果是置顶的分类
                $category->display_order = 255;
            } else {
                $category->display_order > 0 ?  $category->display_order -= 1 :  $category->display_order;
            }
            $category->save();
        }

        $this->back();
    }
}
